package console

import (
	"errors"
	"os"
    
    "collecter/conf"
    "collecter/console/syscommand"
)

func Run(cmd string) error {
	// fmt.Println(os.Args)
	syscommand.NewFlagSet()
	_ = syscommand.FlagSet.String("app", "", "应用名称")
	_ = syscommand.FlagSet.String("cmd", "", "命令名称")

	// fmt.Printf("%+v\n", syscommand.FlagSet)

	commandInstance := conf.Commands[cmd]
	if commandInstance == nil {
		return errors.New("命令 [" + cmd + "]未定义")
	}
	commandInstance.Configure()

	if err := syscommand.FlagSet.Parse(os.Args[3:]); err != nil {
		return err
	}

	return commandInstance.Execute()
}
